package com.wxl.common.util

import android.text.TextUtils
import com.wxl.common.AppContext
import java.io.File

/**
 * create file time : 2021/3/15
 * create user : wxl
 * subscribe :
 */

class FileCommon {
    companion object {

        fun getSdCardRootPath(): String {
           AppContext.appContext.getApplication()
                .getExternalFilesDir(android.os.Environment.DIRECTORY_PICTURES)?.let {
                return it.absolutePath
            }
            return ""
        }

        fun getExternalFileRootPath() : String {
            val rootPath = getSdCardRootPath()
            if(!TextUtils.isEmpty(rootPath)){
                val file = File("$rootPath/dswb")
                if(!file.exists()){
                    file.mkdir()
                }
                return file.absolutePath
            }
            return ""
        }

        fun getExternalImageFile(): File?{
            val path = getExternalFileRootPath()
            if(!TextUtils.isEmpty(path)){
                val dir = File("$path/pic")
                if(!dir.exists()){
                    dir.mkdir()
                }
                val file = File("${dir.absolutePath}/${System.currentTimeMillis()}.png")
                file.createNewFile()
                return file
            }
            return null
        }
    }
}